<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/25
 * Time: 16:14
 */

namespace App;


class Common
{
    //single instance
    private static $instance;

    /**
     * create the single instance
     * @author strong
     * @copyright 2017-6-20
     * @return Common
     */
    public static function getInstance(){
        if(self::$instance === NULL){
            self::$instance = new Common();
        }
        return self::$instance;
    }

    public function resp($status,$error='',$ret=''){
        if($error)
            return array('status'=>$status,'err_msg'=>$error);
        else
            return array('status'=>$status,'ret'=>$ret);
    }

    /**
     * get the page count
     * @author strong
     * @param int $page_size  the size of every page
     * @param int $total_count
     * @return int
     * @internal param $count
     * @internal param the $page_num number of page
     */
    public function getPageCount($page_size, $total_count)
    {
        if($page_size == 0 || $total_count == 0){
            return 0;
        }

        $count = $total_count / $page_size;
        $mod = $total_count % $page_size;

        if($mod == 0){
            return $count;
        }else{
            return intval($count) + 1;
        }
    }


}